package com.cn.icss.validator;

import com.alibaba.fastjson.JSON;
import com.cn.icss.vo.common.ResponseCode;
import com.cn.icss.vo.common.ResponseResult;
import com.cn.icss.vo.common.ResponseStatus;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

import java.util.Map;

/**
 * @中软华腾软件系统有限公司,未经授权不得擅自传播
 * @类描述:
 * @类名称:BaseValidator
 * @作者: Administrator
 * @编辑时间: 2020/05/12 09:45
 * @版本: 1.0
 */
public abstract class BaseValidator extends Validator {

    @Override
    protected void handleError(Controller c) {
        getRet().remove("state");
        // 把最终的错误结果拼装返回到我们自定义的message中
        StringBuffer sb = new StringBuffer();
        Map<String, Object> msgs = super.getRet();
        for (Map.Entry<String, Object> entry : msgs.entrySet()) {
            sb.append(entry.getValue() + ",");
        }
        sb = sb.delete(sb.length() - 1, sb.length());
        ResponseResult responseResult = ResponseResult.build(ResponseCode.Error, sb.toString(), ResponseStatus.FAIL);
        c.renderJson(JSON.toJSONString(responseResult));
    }
}
